package com.shop.cereshop.business.controller;


import com.shop.cereshop.business.annotation.NoRepeatSubmit;
import com.shop.cereshop.business.annotation.NoRepeatWebLog;
import com.shop.cereshop.business.param.billing.CereShopBillingUpdateParam;
import com.shop.cereshop.business.service.billing.CereShopBillingService;
import com.shop.cereshop.commons.constant.CoReturnFormat;
import com.shop.cereshop.commons.domain.billing.CereShopBilling;
import com.shop.cereshop.commons.domain.billing.bo.CereShopBillingBo;
import com.shop.cereshop.commons.domain.billing.vo.CereShopBillingVo;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import com.shop.cereshop.commons.utils.GsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 开单宝模块
 */
@RestController
@RequestMapping("/billing")
/**
 * 注解方式生成日志对象，指定topic生成对象类名
 */
@Slf4j(topic = "CereShopBillingController")
@Api(value = "开单宝模块", tags = "开单宝模块")
public class CereShopBillingController {

    @Autowired
    private CereShopBillingService cereShopBillingService;


    /**
     * 加入开单宝
     */
    @PostMapping("addBilling")
    @NoRepeatSubmit
    @ApiOperation(value = "加入开单宝")
    @NoRepeatWebLog
    public Result addBilling(@RequestBody CereShopBillingBo bo, HttpServletRequest request)  throws CoBusinessException {
        cereShopBillingService.addBilling(bo);
        return new Result(CoReturnFormat.SUCCESS,"加入开单宝", GsonUtil.objectToGson(bo));
    }

    /**
     * 开单宝查询
     * @return
     */
    @GetMapping("getBilling")
    @ApiOperation(value = "开单宝查询")
    public Result<?> getBilling(Long shopId,Long buyerUserId,HttpServletRequest request) throws CoBusinessException{
        List<CereShopBillingVo> cereShopBillingVos = cereShopBillingService.queryList(buyerUserId, shopId);
        return new Result(cereShopBillingVos,CoReturnFormat.SUCCESS);
    }
    /**
     * 修改参数
     * @return
     */
    @PostMapping("updateSku")
    @ApiOperation(value = "修改参数")
    public Result<?> updateSku(@RequestBody CereShopBillingUpdateParam param, HttpServletRequest request) throws CoBusinessException{
        return new Result(cereShopBillingService.updateSku(param),CoReturnFormat.SUCCESS);
    }

}
